package marmalius.tools;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Config {
	private static final Config instance = new Config();
	private String sql_driver;
	private String sql_host;
	private int sql_port;
	private String sql_name;
	private String sql_login;
	private String sql_pass;
	
	private boolean autoCreatePlayer;
	private String serverName;
	private int serverPort;
	private String motd;
	private int maxPlayer;
	private int maxIPPlayer;
	private int logLevel;
	private String logFile;
	private boolean logTime;
	private int maxCycleTime;
	
	
	public String getSql_Driver() { return sql_driver; }
	public String getSql_host() { return sql_host; }
	public int getSql_port() { return sql_port; }
	public String getSql_name() { return sql_name; }
	public String getSql_login() { return sql_login; }
	public String getSql_pass() { return sql_pass; }
	public boolean getAutoCreatePlayer() { return autoCreatePlayer; }
	public String getServerName() { return serverName; }
	public int getServerPort() { return serverPort; }
	public String getMOTD() { return motd; }
	public int getMaxPlayer() { return maxPlayer; }
	public int getMaxIPPlayer() { return maxIPPlayer; }
	public int getLogLevel() { return logLevel; }
	public String getLogFile() { return logFile; }
	public boolean getLogTime() { return logTime; }
	public int getMaxCycleTime() { return maxCycleTime; }
	
	public final static int MAXSTACK = 2147483647;
	public final static int COINID = 995;
	public final static int MAXBANK = 350;
	public final static int ITEMRESPAWNTIME 	= 600000;
	public final static int ITEMALLVISIBLETIME	=  60000; //1 minutes
	public final static int ITEMREMOVETIME		= 300000;
    
	public Config() { }
	
	public boolean loadConfig() {
		try {
			InputStream input = new FileInputStream("config/config.properties");
			Properties prop = new Properties();
			prop.load(input);
			
			sql_driver = prop.getProperty("db.driver", "org.gjt.mm.mysql.Driver");
			sql_host = prop.getProperty("db.host", "localhost");
			sql_port = Integer.parseInt(prop.getProperty("db.port", "3306"));
			sql_name = prop.getProperty("db.name", "marmalius");
			sql_login = prop.getProperty("db.login", "root");
			sql_pass = prop.getProperty("db.password", "");
			
			autoCreatePlayer = Boolean.parseBoolean(prop.getProperty("player.autocreate", "true"));
			serverName = prop.getProperty("server.name", "Marmalius Project");
			serverPort = Integer.parseInt(prop.getProperty("server.port", "43594"));
			motd = prop.getProperty("server.motd", "Bienvenue sur le serveur Marmalius%Pas d'insulte, merci");
			maxPlayer = Integer.parseInt(prop.getProperty("player.max", "100"));
			maxIPPlayer = Integer.parseInt(prop.getProperty("player.ip.max", "3"));
			logLevel = Integer.parseInt(prop.getProperty("server.log.level", "63"));
			logFile = prop.getProperty("server.log.file", "log.txt");
			logTime = Boolean.parseBoolean(prop.getProperty("server.log.time", "true"));
			maxCycleTime = Integer.parseInt(prop.getProperty("server.cycletime", "500"));
			
			input.close();
			return true;
		}
		catch (IOException ex) {
			System.out.println("Error with Config File");
			System.out.println(ex.getMessage());
			return false;
		}
	}
	
	public static Config getInstance() { return instance; }
}
